package indi.zhifa.study2024.class002.busy.dbgen;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import indi.zhifa.study2024.core.mpenhence.entity.po.BaseEntity;
import indi.zhifa.study2024.core.mpenhence.service.IZfDbService;
import indi.zhifa.study2024.core.mpenhence.service.impl.ZfDbServiceImpl;

public class MybatisPlusGenerator {
    public static void main(String[] args) {
        String outputPath =  "E:\\DOCUMENT\\generator\\study2024\\class002";

        FastAutoGenerator.create("jdbc:mysql://192.168.0.64/study2024?useSSL=false&useUnicode=true&characterEncoding=utf-8",
                        "dbMgr", "***@7")
                .globalConfig(builder -> {
                    // 设置作者
                    builder.author("织法")
                            // 开启 swagger 模式
                            .enableSwagger()
                            // 指定输出目录
                            .outputDir(outputPath);
                })
                .packageConfig(builder -> {
                    // 设置父包名
                    builder.parent("indi.zhifa.study2024.class002.busy.generalTest.business.curd")
                            // 指定模块名称
                            .moduleName("inv.storage")
                            .entity("entity.po")
                            .service("dao.service")
                            .serviceImpl("dao.service.impl")
                            .mapper("dao.mapper");

                })
                .strategyConfig(builder -> {
                    // 设置过滤表前缀
                    builder.addInclude("item_inventory")
                            .entityBuilder()
                            .enableLombok()
                            .enableRemoveIsPrefix()
                            .enableFileOverride()
                            .logicDeleteColumnName("del")
                            .logicDeletePropertyName("del")
                            .idType(IdType.ASSIGN_ID)
                            .formatFileName("%sEntity")
                            .superClass(BaseEntity.class)
                            .disableSerialVersionUID()
                            .enableLombok()
                            .javaTemplate("templates/MyEntity.java")
                            .versionColumnName("version")
                            .versionPropertyName("version")
                            .addSuperEntityColumns("id","create_time","create_id","create_name","modify_id","modify_time","modify_name","version","del")
                            .serviceBuilder()
                            .formatServiceFileName("I%sDbService")
                            .formatServiceImplFileName("%sDbServiceImpl")
                            .superServiceClass(IZfDbService.class)
                            .superServiceImplClass(ZfDbServiceImpl.class)
                            .serviceImplTemplate("templates/MyServiceImpl.java")
                            .serviceTemplate("templates/MyService.java")
                            .mapperBuilder()
                            .mapperTemplate("templates/MyMapper.java")
                            .controllerBuilder()
                            .disable();
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
